{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 报表分析\n",
    "\n",
    "从大盘指标的基本面数据提取给定代码的历史数据。\n",
    "\n",
    "分为两个维度：\n",
    "- 提取当期的不同指标，反映当期的各方面情况和均衡性。\n",
    "- 提取同一指标的时间序列，反映单项指标的变化和成长性。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getData():\n",
    "    print(\"Get profit data...\")\n",
    "    profit = ts.get_profit_data(2018,1)\n",
    "    profit.to_csv(\"./finadata/profit201801.csv\")\n",
    "    print(\"Finished.\")\n",
    "\n",
    "    print(\"Get profit data...\")\n",
    "    debt = ts.get_debtpaying_data(2018,1)\n",
    "    debt.to_csv(\"./finadata/debt201801.csv\")\n",
    "    print(\"Finished.\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Get profit data...\n",
      "[Getting data:]###########################################################Finished.\n",
      "Get profit data...\n",
      "[Getting data:]###########################################################Finished.\n"
     ]
    }
   ],
   "source": [
    "getData()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "def loadData(code,year,season):\n",
    "    profit = pd.read_csv(\"./finadata/profit201801.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "profit = pd.read_csv(\"./finadata/profit201801.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Unnamed: 0', 'code', 'name', 'roe', 'net_profit_ratio',\n",
       "       'gross_profit_rate', 'net_profits', 'eps', 'business_income', 'bips'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "profit.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>code</th>\n",
       "      <th>name</th>\n",
       "      <th>roe</th>\n",
       "      <th>net_profit_ratio</th>\n",
       "      <th>gross_profit_rate</th>\n",
       "      <th>net_profits</th>\n",
       "      <th>eps</th>\n",
       "      <th>business_income</th>\n",
       "      <th>bips</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2466</th>\n",
       "      <td>2466</td>\n",
       "      <td>300036</td>\n",
       "      <td>超图软件</td>\n",
       "      <td>0.7</td>\n",
       "      <td>5.4</td>\n",
       "      <td>52.721</td>\n",
       "      <td>12.767</td>\n",
       "      <td>0.0284</td>\n",
       "      <td>236.2086</td>\n",
       "      <td>0.5254</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0    code  name  roe  net_profit_ratio  gross_profit_rate  \\\n",
       "2466        2466  300036  超图软件  0.7               5.4             52.721   \n",
       "\n",
       "      net_profits     eps  business_income    bips  \n",
       "2466       12.767  0.0284         236.2086  0.5254  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "profit[profit[\"code\"]==300036]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>name</th>\n",
       "      <th>currentratio</th>\n",
       "      <th>quickratio</th>\n",
       "      <th>cashratio</th>\n",
       "      <th>icratio</th>\n",
       "      <th>sheqratio</th>\n",
       "      <th>adratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1096</th>\n",
       "      <td>300036</td>\n",
       "      <td>超图软件</td>\n",
       "      <td>2.6029</td>\n",
       "      <td>2.5816</td>\n",
       "      <td>65.4612</td>\n",
       "      <td>1268.12</td>\n",
       "      <td>72.4788</td>\n",
       "      <td>27.5212</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        code  name currentratio quickratio cashratio  icratio  sheqratio  \\\n",
       "1096  300036  超图软件       2.6029     2.5816   65.4612  1268.12    72.4788   \n",
       "\n",
       "      adratio  \n",
       "1096  27.5212  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "debt[debt[\"code\"]==\"300036\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
